package clearsyntax.types;

public final class IntegerRange extends AbstractRange<Integer> {

	public IntegerRange(int start, int end, int step) {
		super(start, end, step);
		checkLength();
	}

	@Override
	public IntegerRange by(int step) {
		return new IntegerRange(start(), end(), step);
	}

	@Override
	public Integer get(int index) {
		checkIndex(index);
		return start() + (step() * index);
	}

	@Override
	protected int toCode(Integer value) {
		return value;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + start();
		result = prime * result + end();
		result = prime * result + step();
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		final IntegerRange that = (IntegerRange) obj;
		if (!this.start().equals(that.start())) {
			return false;
		}
		if (!this.end().equals(that.end())) {
			return false;
		}
		if (this.step() != that.step()) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return "Range(" + start() + ", " + end() + ", " + step() + ")";
	}

}